﻿using System;
using System.Data;
using Besture.Bll;

namespace Besture.UI.Admin.Master
{
    public partial class Admin_bak : System.Web.UI.MasterPage
    {
        public string _Title { get; set; }

        /// <summary>
        /// 当前模块ID
        /// </summary>
        public string curModulesId = string.Empty;
        /// <summary>
        /// 当前模块名
        /// </summary>
        public string curModulesName = string.Empty;
        /// <summary>
        /// 当前页面ID
        /// </summary>
        public string curPageId = string.Empty;
        /// <summary>
        /// 当前页面名称
        /// </summary>
        public string curPageName = string.Empty;

        AdminPagesDac adminPagesDac = new AdminPagesDac();

        protected void Page_Load(object sender, EventArgs e)
        {

            //临时写法
            DataTable tableModules = new DataTable();

            string curUrl = Request.Url.LocalPath.ToLower();
            curUrl = curUrl.Substring(curUrl.IndexOf("/admin"));
            if (curUrl.IndexOf("key=") == -1 && curUrl.IndexOf("longcontent") == -1)
            {
                curUrl = curUrl.Replace("set.aspx", "list.aspx");
            }

            if (curUrl.IndexOf("partcontentlist.aspx") > -1)
            {
                curUrl = Request.Url.PathAndQuery.ToLower().ToString();
            }

            tableModules = adminPagesDac.GetDataTableByUrl(curUrl);
            if (tableModules.Rows.Count == 0)
            {
                curUrl = Request.Url.PathAndQuery.ToLower();
                curUrl = curUrl.Substring(curUrl.IndexOf("/admin"));
                if (curUrl.IndexOf("key=") == -1 && curUrl.IndexOf("longcontent") == -1)
                {
                    curUrl = curUrl.Replace("set.aspx", "list.aspx");
                }
                tableModules = adminPagesDac.GetDataTableByUrl(curUrl);
            }
            if (tableModules.Rows.Count > 0)
            {
                //临时写法
                curModulesId = tableModules.Rows[0]["ModulesID"].ToString();
                curModulesName = tableModules.Rows[0]["ModulesName"].ToString();
                curPageId = tableModules.Rows[0]["id"].ToString();
                curPageName = tableModules.Rows[0]["Name"].ToString();

            }
            BindData();

        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindData()
        {
            rpModules.DataSource = AdminUserService.AdminLoginUser.tableModulesPermissions;
            rpModules.DataBind();
            if (!string.IsNullOrEmpty(curModulesId))
            {
                //DataTable tablePages =  adminPagesDac.GetDataTableByModulesId(curModulesId);
                rpPages.DataSource = AdminUserService.GetPageTableByModulesId(curModulesId);
                rpPages.DataBind();
            }
        }

        protected void lbUpdatePassword_Click(object sender, EventArgs e)
        {

        }

        protected void lbOut_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 判断是否当前模块
        /// </summary>
        /// <param name="modulesID"></param>
        /// <returns></returns>
        public string IsCurModules(string modulesID)
        {
            if (string.IsNullOrEmpty(curModulesId))
            {
                //if (Session["curModulesId"] != null)
                //{
                if (curModulesId.Equals(modulesID))
                {
                    return "class='selected'";
                }
                //}
            }
            else if (curModulesId.Equals(modulesID))
            {
                return "class='selected'";
            }
            return "";
        }

        /// <summary>
        /// 判断是否当前页面
        /// </summary>
        /// <param name="pageID"></param>
        /// <returns></returns>
        public string IsCurPages(string pageID)
        {
            if (string.IsNullOrEmpty(pageID))
            {
                //if (Session["curPageId"] != null)
                //{
                if (curPageId.Equals(curPageId))
                {
                    return "class='selected'";
                }
                //}
                return "";
            }
            else if (curPageId.Equals(pageID))
            {
                return "class='selected'";
            }
            return "";
        }
    }
}